<template>
    <div class="app-container">
        <div class="search-container">
            <el-form v-show="showSearch" ref="queryParamsRef" :inline="true" :model="queryParams" label-width="100px">
                <el-form-item label="手术编码类型" prop="diagnosisOperType">
                    <el-select class="width-120" v-model="queryParams.diagnosisOperType" clearable
                        placeholder="请选择手术编码类型" @change="getList">
                        <el-option v-for="dict in dictDataMap['operation_code_dict']" :key="dict.dictValue"
                            :label="dict.dictLabel" :value="dict.dictValue" />
                    </el-select>
                </el-form-item>
                <el-form-item label="手术编码" prop="operationCode">
                    <el-input v-model="queryParams.operationCode" clearable placeholder="请输入手术编码"
                        @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item label="手术名称" prop="operationName">
                    <el-input v-model="queryParams.operationName" clearable placeholder="请输入手术名称"
                        @keyup.enter.native="handleQuery" />
                </el-form-item>
                <div style="float: right" class="mr20">
                    <query-form-button @handleQuery="handleQuery" @resetQuery="resetQuery" />
                </div>
            </el-form>
        </div>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button v-hasPerm="['base:operationDictIcd10:add']" plain type="primary" @click="handleAdd"><template
                        #icon>
                        <i-ep-plus />
                    </template>新增
                </el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button v-hasPerm="['base:operationDictIcd10:edit']" :disabled="single" plain type="success"
                    @click="handleUpdate"><template #icon>
                        <i-ep-edit />
                    </template>修改
                </el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button v-hasPerm="['base:operationDictIcd10:remove']" :disabled="multiple" plain type="danger"
                    @click="handleDelete"><template #icon>
                        <i-ep-delete />
                    </template>删除
                </el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button v-hasPerm="['base:operationDictIcd10:export']" plain type="warning"
                    @click="handleExport"><template #icon>
                        <i-ep-download />
                    </template>导出
                </el-button>
            </el-col>
        </el-row>

        <el-table v-adaptive :data="operationDictIcd10List" :border="true" :stripe="true" highlight-current-row
            @selection-change="handleSelectionChange" :header-cell-style="$headerCellStyle">
            <el-table-column :align="'center'" type="selection" width="55" />
            <el-table-column :align="'center'" label="手术编码类型" prop="diagnosisOperType">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['operation_code_dict']" :value="scope.row.diagnosisOperType" />
                </template>
            </el-table-column>
            <el-table-column :align="'center'" label="手术编码" prop="operationCode" />
            <el-table-column :align="'center'" label="手术名称" prop="operationName" />
            <el-table-column :align="'center'" label="手术规模" prop="operationScale">
                <template #default="scope">
                    <dict-data-tag :options="dictDataMap['operation_scale']" :value="scope.row.operationScale" />
                </template>
            </el-table-column>
            <el-table-column :align="'center'" label="迹象" prop="stdIndicator" />
            <el-table-column :align="'center'" label="经核准的迹象" prop="approvedIndicator" />
            <el-table-column :align="'center'" label="备注" prop="remark" />
            <el-table-column :align="'center'" class-name="small-padding fixed-width" label="操作">
                <template #default="scope">
                    <el-button v-hasPerm="['base:operationDictIcd10:edit']" type="success"
                        @click="handleUpdate(scope.row)"><template #icon>
                            <i-ep-edit />
                        </template>修改
                    </el-button>
                    <el-button v-hasPerm="['base:operationDictIcd10:remove']" type="danger"
                        @click="handleDelete(scope.row)"><template #icon>
                            <i-ep-delete />
                        </template>删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" v-model:limit="queryParams.pageSize" v-model:page="queryParams.pageNum"
            :total="total" @pagination="getList" />

        <!-- 添加或修改手术基础字典多个类型对话框 -->
        <el-dialog :close-on-click-modal="false" :title="title" v-model="open" append-to-body width="900px">
            <el-form ref="formRef" :model="form" :rules="rules" label-width="120px">
                <el-row :gutter="40">
                    <el-col :span="12">
                        <el-form-item label="手术编码类型" prop="diagnosisOperType">
                            <el-select v-model="form.diagnosisOperType" placeholder="请选择手术编码类型" style="width: 100%">
                                <el-option v-for="dict in dictDataMap['operation_code_dict']" :key="dict.dictValue"
                                    :label="dict.dictLabel" :value="dict.dictValue"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="手术编码" prop="operationCode">
                            <el-input v-model="form.operationCode" placeholder="请输入手术编码" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="手术名称" prop="operationName">
                            <el-input v-model="form.operationName" placeholder="请输入手术名称" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="手术规模" prop="operationScale">
                            <el-select v-model="form.operationScale" placeholder="请输入手术规模" style="width: 100%">
                                <el-option v-for="dict in dictDataMap['operation_scale']" :key="dict.dictValue"
                                    :label="dict.dictLabel" :value="dict.dictValue"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="迹象" prop="stdIndicator">
                            <el-input v-model="form.stdIndicator" placeholder="请输入迹象" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="经核准的迹象" prop="approvedIndicator">
                            <el-input v-model="form.approvedIndicator" placeholder="请输入经核准的迹象" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="拼音码" prop="inputCode">
                            <el-input v-model="form.inputCode" placeholder="请输入拼音码" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="备注" prop="remark">
                            <el-input v-model="form.remark" placeholder="请输入内容" type="textarea" />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button type="primary" @click="submitForm">确 定</el-button>
                    <el-button @click="cancel">取 消</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script lang="ts" setup>
import {
    addOperationDictIcd10,
    delOperationDictIcd10,
    getOperationDictIcd10,
    selectPageOperationDictIcd10,
    updateOperationDictIcd10
} from "@/api/base/operationDictIcd10";
import { useDictStoreHook } from "@/store/modules/dict";
import { useUserStoreHook } from "@/store/modules/user"
const formRef = ref()
const useUserStore = useUserStoreHook();
const dictStore = useDictStoreHook();
const dictDataMap = ref(dictStore.isTypeGetData('operation_code_dict', 'operation_scale'))
// 按钮loading
const buttonLoading = ref(false)
// 选中数组
const ids = ref([])
// 非单个禁用
const single = ref(true)
// 非多个禁用
const multiple = ref(true)
// 显示搜索条件
const showSearch = ref(true)
// 总条数
const total = ref(0)
// 手术基础字典多个类型表格数据
const operationDictIcd10List = ref([])
// 弹出层标题
const title = ref("")
// 是否显示弹出层
const open = ref(false)
// 查询参数
const queryParamsRef = ref()
const queryParams = ref<any>({
    pageNum: 1,
    pageSize: 10,
    operationCode: undefined,
    operationName: undefined,
    operationScale: undefined,
    stdIndicator: undefined,
    approvedIndicator: undefined,
    diagnosisOperType: undefined,
    inputCode: undefined,
    remark: undefined
})
// 表单参数
const form = ref<any>({})
// 表单校验
const rules = ref({
    operationDictId: [
        { required: true, message: "主键不能为空", trigger: "blur" }
    ],
    operationCode: [
        { required: true, message: "手术编码不能为空", trigger: "blur" }
    ],
    operationName: [
        { required: true, message: "手术名称不能为空", trigger: "blur" }
    ],
    // operationScale: [
    //     {required: true, message: "手术规模不能为空", trigger: "blur"}
    // ],
    diagnosisOperType: [
        { required: true, message: "手术编码类型不能为空", trigger: "change" }
    ],
})
getList()
/** 查询手术基础字典多个类型列表 */
function getList() {
    selectPageOperationDictIcd10(queryParams.value).then((response: any) => {
        operationDictIcd10List.value = response.rows;
        total.value = response.total;
    });
}
// 取消按钮
function cancel() {
    open.value = false;
    reset();
}
// 表单重置
function reset() {
    form.value = {
        operationDictId: undefined,
        operationCode: undefined,
        operationName: undefined,
        operationScale: undefined,
        stdIndicator: undefined,
        approvedIndicator: undefined,
        diagnosisOperType: undefined,
        inputCode: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        updateBy: undefined,
        delFlag: undefined,
        remark: undefined
    };
}
/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}
/** 重置按钮操作 */
function resetQuery() {
    queryParamsRef.value.resetFields()
    handleQuery();
}
// 多选框选中数据
function handleSelectionChange(selection) {
    ids.value = selection.map(item => item.operationDictId)
    single.value = selection.length !== 1
    multiple.value = !selection.length
}
/** 新增按钮操作 */
function handleAdd() {
    reset();
    open.value = true;
    title.value = "添加手术基础字典多个类型";
}
/** 修改按钮操作 */
function handleUpdate(row) {
    reset();
    const operationDictId = row.operationDictId || ids.value
    getOperationDictIcd10(operationDictId).then(response => {
        form.value = response.data;
        open.value = true;
        title.value = "修改手术基础字典多个类型";
    });
}
/** 提交按钮 */
function submitForm() {
    (formRef.value as any).validate(valid => {
        if (valid) {
            buttonLoading.value = true;
            if (form.value.operationDictId != null) {
                updateOperationDictIcd10(form.value).then(_response => {
                    ElMessage.success("修改成功");
                    open.value = false;
                    getList();
                }).finally(() => {
                    buttonLoading.value = false;
                });
            } else {
                addOperationDictIcd10(form.value).then(_response => {
                    ElMessage.success("新增成功");
                    open.value = false;
                    getList();
                }).finally(() => {
                    buttonLoading.value = false;
                });
            }
        }
    });
}
/** 删除按钮操作 */
function handleDelete(row) {
    const operationDictIds = row.operationDictId || ids.value;
    ElMessageBox.confirm('是否确认删除手术基础字典多个类型编号为"' + operationDictIds + '"的数据项？',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
    ).then(() => {
        delOperationDictIcd10(operationDictIds).then(() => {
            getList();
            ElMessage.success("删除成功");
        })
    }).catch(() => {
    })
}
/** 导出按钮操作 */
function handleExport() {
    // download('base/operationDictIcd10/export', {
    //     ...queryParams
    // }, `operationDictIcd10_${new Date().getTime()}.xlsx`)
}
</script>
<script lang="ts">
export default {
    name: "OperationDictIcd10"
};
</script>
